package org.languageguide.media;


public class Mobile5MediaGenerator implements MediaGenerator {
	
	public static final String irJavascript = "<script src=\"irmobilehtml5.js\"></script>\n<link href=\"/applets/mobile.css\" rel=\"stylesheet\" type=\"text/css\" />";
	public static final String ir2Javascript = "<script src=\"/applets/ir2mobilehtml5.js\"></script>\n<link href=\"/applets/mobile.css\" rel=\"stylesheet\" type=\"text/css\" />";	
	public static final String ir3Javascript = "<script src=\"ir3mobilehtml5.js\"></script>\n<link href=\"/applets/mobile.css\" rel=\"stylesheet\" type=\"text/css\" />";	
	
	boolean hidef = false;
	public Mobile5MediaGenerator(boolean hidef){
		hidef = true;
	}
	
	/*public static String[] generate(String language, String name, boolean premium){
		String[] media = new String[2];
		return media;
	}*/
	
	
	
	public String[] getIrTags(String soundFile){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root2_mobil_apple + soundFile;
		String[] media = new String[2];
		media[0] = irJavascript;
		media[1] = getHTML5Tag(soundFile, true);
		return media;
	}
	
	
	
	
	public static String getHTML5Tag(String soundFile, boolean autostart){
		String autoStartStr; 
		if (autostart){
			autoStartStr = "autoplay=\"true\"";
		}
		else{
			autoStartStr = "";
		}
		String audio = "<audio id=\"player\" " + autoStartStr + " controls=\"true\">" +
		"<source src=\"" + soundFile + "\" type=\"audio/mp4\">" + 
		"</audio>";
		return audio;
	}

	
	

	public String getKey(){
		if (!hidef)
			return "30";
		else return "31";
	}
	
	public String getOldKey(){
			return "3";
	}

	@Override
	public String[] getIr(String soundFile) {
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root_mobil_apple + soundFile;//; + ".m4a";
		String[] media = new String[2];
		media[0] = irJavascript;
		media[1] = getHTML5Tag(soundFile,true);
		return media;
	}
	
	public String[] getIR2(String soundFile) {
		if (!hidef){
			soundFile = Utility.root + soundFile + ".m4a";
		}
		else soundFile = Utility.root + soundFile + "-hi.m4a";
		String[] media = new String[2];
		media[0] = ir2Javascript;
		media[1] = getHTML5Tag(soundFile,false);
		return media;
	}
	
	public String[] getIR3(String soundFile) {
		//soundFile = Utility.convertwma(soundFile);

		System.out.println("hidef" + hidef);
		String[] media = new String[2];
		media[0] = ir3Javascript;
		System.out.println("soundFile" + soundFile);
		media[1] = HTML5MediaGenerator.getHTML5Tag(soundFile,false, false);
		return media;
	}
	
	public boolean useSvg(){
		return true;
	}

}